﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;
using ScrumTable.Common.Collections;

#endregion

namespace ScrumTable.DL.Data.Common
{
    /// <summary>
    /// Represents the method that handles the DataAccessObject changed event.
    /// </summary>
    /// <param name="sender">Specifies the DataAccessObject sender of the event.</param>
    /// <param name="e">Arguments which contain information about the event.</param>
    public delegate void DataAccessObjectChangedEventHandler(object sender, DataAccessObjectChangedEventArgs e);

    /// <summary>
    /// Describes the action that caused a DataAccessObjectChangedAction event.
    /// </summary>
    public enum DataAccessObjectChangedAction
    {
        /// <summary>
        /// One item was added to the collection.
        /// </summary>
        Add,

        /// <summary>
        /// One item was removed from the collection.
        /// </summary>
        Remove
    } 


    /// <summary>
    /// Represents the an event arguments class which contains additional
    /// information about an event if something has changed inside a
    /// DataAccessObject.
    /// </summary>
    public class DataAccessObjectChangedEventArgs : EventArgs
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Specifies the action that caused the change.
        /// </summary>
        public DataAccessObjectChangedAction Action { get; private set; }

        /// <summary>
        /// Specifies the unique parent key chain of the changed data access
        /// object.
        /// </summary>
        public ValueChain<string> ParentIdChain { get; private set; }

        /// <summary>
        /// Specifies the id chain of the changed data object.
        /// </summary>
        public ValueChain<string> ItemIdChain { get; private set; }

        /// <summary>
        /// Specifies the changed data object.
        /// </summary>
        public IDataObject ChangedItem { get; private set; }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DataAccessObjectChangedEventArgs instance.
        /// </summary>
        /// <param name="action">Specifies the change action of the element.</param>
        /// <param name="parentChain">Specifies the chain of the item which has caused the change.</param>
        /// <param name="changedItem">Specifies the item which has caused the change.</param>
        public DataAccessObjectChangedEventArgs(DataAccessObjectChangedAction action, ValueChain<string> parentChain, IDataObject changedItem)
        {
            PreCondition.AssertNotNull(parentChain, "parentChain");
            PreCondition.AssertNotNull(changedItem, "changedItem");

            Action = action;
            ItemIdChain = new ValueChain<string>(parentChain, changedItem.Id);
            ChangedItem = changedItem;
            ParentIdChain = parentChain;
        }

        /// <summary>
        /// Creates a new DataAccessObjectChangedEventArgs instance.
        /// </summary>
        /// <param name="action">Specifies the change action of the element.</param>
        /// <param name="parentChain">Specifies the chain of the item which has caused the change.</param>
        /// <param name="changedItemId">Specifies the item id which has caused the change.</param>
        public DataAccessObjectChangedEventArgs(DataAccessObjectChangedAction action, ValueChain<string> parentChain, string changedItemId)
        {
            PreCondition.AssertNotNull(parentChain, "parentChain");
            PreCondition.AssertNotNull(changedItemId, "changedItemId");

            Action = action;
            ItemIdChain = new ValueChain<string>(parentChain, changedItemId);
            ParentIdChain = parentChain;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------
        
        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}